package basic50.fortieth;

import java.util.Scanner;

public class Basic37 {
    public static void main(String[] args) {
        //题目：有n个人围成一圈，顺序排号。从第一个人开始报数（从1到3报数），凡报到3的人退出圈子，问最后留下的是原来第几号的那位
        Scanner input = new Scanner(System.in);
        System.out.print("Enter an integer: ");
        int num = input.nextInt();
        int index = lastIndex(num);
        System.out.println(index);
    }

    public static int lastIndex(int num) {
        if(num == 1){
            return 1;
        }
        return (3 + lastIndex(num-1) -1) % num + 1;
    }
}
